package com.atguigu.lease.web.admin.interceptors;

import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.common.springmvc.leaseException;
import com.atguigu.lease.common.utils.JwtUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.servlet.HandlerInterceptor;

public class Logininterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       //获取token
        String accessToken = request.getHeader("access_token");
        if (ObjectUtils.isEmpty(accessToken)) {
            throw new leaseException(ResultCodeEnum.ADMIN_LOGIN_AUTH);
        }
          //  有token,检查是否有效过期
            JwtUtil.parseToken(accessToken);
            return true;
        }
    }
